<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/common/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
    <title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
    <%@ include file="/WEB-INF/view/common/css_js_ace.jsp" %>
    <link rel="stylesheet" href="${ctx}/static/ace/css/chosen.css"/>
    <script type="text/javascript">
	    $(function() {
	    	if("${param.userType}" == "2"){
	    		$("#node").attr("checked",true);
	    	}else if("${param.userType}" == "0"){
	    		$("#sys").attr("checked",true);
	    	}else{
	    		$("#all").attr("checked",true);
	    	}
	    	changeUserType();
	    });
	    function search(form) {
	    	$(form).appendPagerParaStr();
	    	return true;
	    }
        function resetPwd(id){
        	if(!window.confirm("确定将所选用户密码重置为初始密码吗？")){
        		return;
        	}
            $.ajax({
                type: "POST",
                url:_ctx + "/usermgr/reset_pwd/" + id + ".do",
                success: function (resp) {
                    if (resp.status == '1') {
                        ui.msg(resp.msg, 1);
                    } else {
                        ui.msg(resp.msg, 0);
                    }
                },
                error: function () {
                    ui.msg('信息加载错误', 0);
                }
            });
        }
        function deleteById(id){
        	ui.confirm("确认删除?",function(){
        		$.ajax({
        			   type: "POST",
        			   dataType:"json",
        			   cache: false,
        			   url: _ctx + "/usermgr/user_delete.do",
        			   data: {id:id},
        			   success: function(resp){
        				   if(resp.status == '1'){
        					   ui.msg(resp.msg, 1);
        					   ui.go(_ctx + "/usermgr/user_list.do");
        				   }else{
        					   ui.msg(resp.msg, 0);
        				   }
        			   },
        			   error:function(){
        				   ui.msg('信息加载错误', 0);
        			   }
        		});
        	});	
        }
       function changeUserType(){
    	  var userType = $('input[name="userType"]:checked').val();
    	   if(userType == "2"){
    		   $("#ownId").val("${nodeInfo.id}");
    		   $("#sysId").css("display","none");
    	   }else if( userType == "0"){
    		   $("#ownId").val("");
    		   $("#sysId").css("display","");
    	   }else{
    		   $("#ownId").val("");
    		   $("#sysId").css("display","none");
    	   }
       }
        function changeSys(){
        	$("#ownId").val($("#sysId").val());
        }
    </script>
</head>
<body>
<%@ include file="/WEB-INF/view/common/topbar.jsp" %>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <%@ include file="/WEB-INF/view/common/sidebar.jsp" %>
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="icon-home home-icon"></i>
                        <a href="#">首页</a>
                    </li>
                    <li>
                        <a href="#">系统管理</a>
                    </li>
                    <li>
                        <a href="#">用户管理</a>
                    </li>
                    <li class="active">列表</li>
                </ul>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget-box">
                            <div class="widget-header header-color-white">
                                <div class="widget-toolbar no-border">
									<a class="btn btn-primary btn-xs" href="${ctx}/usermgr/user_add.do" ><i class="icon-plus-sign icon-on-right"></i> 新增&nbsp;&nbsp;</a>
                                </div>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main">
                                    <form id="searchForm" class="form-search"
                                          action="${ctx }/usermgr/user_list.do" method="post"
                                          onsubmit="return search(this)">
                                        <div class="row">
                                        	<div class="col-xs-7">
												<div class="input-group "  style="text-align: left;">
													<span class="input-group-addon " style="text-align: left;">用户类型&nbsp;&nbsp;
															<input type="radio" name="userType" class="ace" id="all" onclick="javascript:changeUserType();" value="" checked="checked"> 
															<span class="lbl">&nbsp;全部</span>
															<input type="radio" name="userType" class="ace" id="node" onclick="javascript:changeUserType();" value="2"> 
															<span class="lbl">&nbsp;节点用户</span>
															<input type="radio" name="userType" class="ace" id="sys" onclick="javascript:changeUserType();" value="0" > 
															<span class="lbl">&nbsp;适配器用户</span>
													 </span>
													 <input type="hidden" id="ownId" name="ownId" value="">
													 <select name="sysId" id="sysId"  class="form-control search-query"  style="height: 34px;display: none;" onchange="changeSys();">
	                                                        <option value="">-请选择-</option>
	                                                        <c:forEach var="vo" items="${adapterList}">
	                                                            <option value='${vo.id}'
	                                                             <c:if test="${vo.id==param.ownId}">selected</c:if>>${vo.adapterName}</option>
	                                                        </c:forEach>
	                                                    </select>
	                                                    <span class="input-group-btn">
															<button type="submit" class="btn btn-purple btn-sm"
                                                                    onclick="return formSubmit();" style="height:34px;">
                                                                <i class="icon-search icon-on-right bigger-110"></i>
                                                                                                                                                                            搜索
                                                            </button>
                                                     </span>
												</div>
											</div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div class="hr hr12 hr-dotted"></div>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="center">序号</th>
                                    <th>用户名</th>
                                    <th>用户类型</th>
                                    <th>修改时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="vo" items="${sysUsers}" varStatus="idx">
                                    <tr>
                                        <td class="center">${idx.index + 1}</td>
                                        <td>${vo.userName}</td>
                                         <td>${si:ctname("USER_TYPE",vo.userType )}
	                                         <c:if test="${ vo.userType eq 0}">
	                                        	(${vo.userNameStr})
	                                        </c:if>
                                        </td>
                                         <td>${si:fmtDate(vo.mtime)}</td>
                                        <td>
                                            <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                                <a class="blue" href="javascript:void(0)"
                                                   onclick="resetPwd('${vo.id}')" title="重置密码">
                                                    <i class="icon-undo bigger-130"></i>
                                                </a>
                                                <a class="green" href="${ctx}/usermgr/user_update/${vo.id }.do" title="修改">
													<i class="icon-pencil bigger-130"></i>
												</a>
                                                <a class="red"  href="javascript:void(0);" onclick="deleteById('${vo.id }')" title="删除">
												<i class="icon-trash bigger-130"></i> 
											</a>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <jsp:include page="/WEB-INF/view/common/pg.jsp">
								<jsp:param value="${ctx }/usermgr/user_list.do" name="url"/>
								<jsp:param value="${_total}" name="total"/>
								<jsp:param value="${_urlpara}" name="urlpara" />
						    </jsp:include>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
